package com.dongdongshop.service.impl;

import com.dongdongshop.data.PageBean;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class BrandServiceImpl implements BrandService {

    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public PageBean<TbBrand> findList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> brandList = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> pb = new PageInfo<>(brandList);
        return new PageBean<TbBrand>(pb.getPageNum(),pb.getPageSize(),pb.getTotal(),pb.getPages(),pb.getList());
    }

    @Override
    public TbBrand selectById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBrand(TbBrand tbBrand) {
        tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public void addBrand(TbBrand tbBrand) {
        tbBrandMapper.insertSelective(tbBrand);
    }

    @Override
    public void deleteBrand(Long[] id) {
        tbBrandMapper.deleteBrand(id);
    }
}
